package main

import (
	"fmt"
	"net"
)

func main() {
	// 拨号建联
	conn, err := net.Dial("tcp", "124.221.184.53:8080")
	if err != nil {
		fmt.Println(err)
	}
	defer conn.Close()
	// 接收欢迎信息
	rst := make([]byte, 1024)
	n, err := conn.Read(rst)
	fmt.Println(string(rst[:n]))

	for {
		// 发送聊天信息
		fmt.Printf("输入聊天信息,q退出：")
		var sendmsg string
		fmt.Scanln(&sendmsg)

		// q退出
		if sendmsg == "q" {
			break
		}
		conn.Write([]byte(sendmsg))

		//接收聊天信息
		rstmsg := make([]byte, 1024)
		n, err := conn.Read(rstmsg)
		if err != nil {
			fmt.Println(err)
		}

		fmt.Println(string(rstmsg[:n]))

	}
}
